package com.tanavlog.web.controller;

import com.tanavlog.common.response.CommonResult;
import com.tanavlog.web.dto.request.RegistryUserInfoCheckDTO;
import com.tanavlog.web.dto.response.UserUniqueCheckResult;
import com.tanavlog.web.service.RegistryLoginService;
import com.tanavlog.web.validation.RegistryInfoCheckGroupOne;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author fenghualian
 * @description 用户信息控制器
 * @since 2025/7/24 19:53
 */
@RestController
@RequestMapping("/users")
public class UserInfoController {

    @Autowired
    private RegistryLoginService registryLoginService;

    @PostMapping("/check-unique")
    public CommonResult<UserUniqueCheckResult> checkUnique(@RequestBody @Validated(RegistryInfoCheckGroupOne.class) RegistryUserInfoCheckDTO  registryUserInfoCheckDTO) {
        return CommonResult.success(registryLoginService.checkUserInfo(registryUserInfoCheckDTO));
    }

    @GetMapping("/send-verify-code")
    public CommonResult<Object> sendVerifyCode(@RequestParam String emailAddress) {
        // todo: 使用CommonResultSimple去返回结果，并定义一个发送验证码的枚举实例
        return CommonResult.success(registryLoginService.sendVerifyCode(emailAddress));
    }

}
